﻿addLoadEvent(autoSize);
addLoadEvent(getClipInput);

//addLoadEvent(bindPopBtn);
addPreloadEvent(bindPopBtn);

function bindPopBtn(){
    var viewItem=$("bookItem");
    if(viewItem==null)return;
    var linkSWF=$a.call(viewItem,"a");
    if(linkSWF==null)return;
    
    linkSWF.onclick=clickHander;
    
    var buyActionObj=$("buyAction");
    if(buyActionObj==null)return;
    var buyBtnAuthor=$a.call(buyActionObj,"a");
    buyBtnAuthor.onclick=function(){
        var url=this.href||this.getAttribute("herf");
        popnew(url,"buy",650,470);
        return false;
    }
    
    return;
}
function clickHander(){
    /*RunSWF(this.href);*/
    viewerWin=window.open(this.href, "qzViewer", "top=0,left=0,status=0,width=" + screen.width + ", height=" + (screen.height-60))
    return false;
}

function autoSize(){
    var viewContent=$("viewContent");
    if(viewContent==null)return;
    var imgList=$as.call(viewContent,"img");
    var len=imgList.length;
    for(var i=0;i<len;i++){
        //alert(imgList[i].width);
        if(imgList[i].width>530||imgList[i].style.width>530){
            imgList[i].width=530;//firefox;
            imgList[i].style.width=530;
            imgList[i].style.height="auto";
        }
    }
}

function getClipInput(){
    var urlInput=$("viewAddress");
    if(urlInput==null)return;
    setClipInput(urlInput);
    
    var blogCode=$("blogCode");
    if(blogCode==null)return;
    setClipInput(blogCode);
}


function setClipInput(input){
    input.onmouseover=function(){
        this.select();
        this.style.borderColor="#f9c"
    }
   input.onmouseout=function(){
        this.style.borderColor="#ccc";
    }
    input.onmousedown=function(){
        var js=this.createTextRange();
        if(js.execCommand("Copy")){
            alert("复制成功，您可以粘贴（Ctrl+V）到QQ或MSN上推荐给好友。");
        }else{
            alert("您已禁用了本站的复制");
        }
    }
}